nginx-ingress examples

  1. rewrites

    https://github.com/nginxinc/kubernetes-ingress/tree/v1.8.1/examples/rewrites

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: cafe-ingress
      annotations:
        nginx.org/rewrites: "serviceName=tea-svc rewrite=/;serviceName=coffee-svc rewrite=/beans/"
    spec:
      rules:
      - host: cafe.example.com
        http:
          paths:
          - path: /tea/
            backend:
              serviceName: tea-svc
              servicePort: 80
          - path: /coffee/
            backend:
              serviceName: coffee-svc
              servicePort: 80
    
  2. rewrites

    https://github.com/nginxinc/kubernetes-ingress/tree/v1.8.1/examples-of-custom-resources/rewrites

    apiVersion: k8s.nginx.org/v1
    kind: VirtualServer
    metadata:
      name: cafe
    spec:
      host: cafe.example.com
      upstreams:
      - name: tea
        service: tea-svc
        port: 80
      - name: coffee
        service: coffee-svc
        port: 80
      routes:
      - path: /tea/
        action:
          proxy:
            upstream: tea
            rewritePath: /
      - path: /coffee
        action:
          proxy:
            upstream: coffee
            rewritePath: /beans
    
  3. snippets

    https://docs.nginx.com/nginx-ingress-controller/configuration/ingress-resources/advanced-configuration-with-snippets/

    apiVersion: networking.k8s.io/v1beta1
    kind: Ingress
    metadata:
      name: cafe-ingress-with-snippets
      annotations:
        nginx.org/server-snippets: |
          location / {
              return 302 /coffee;
          }
        nginx.org/location-snippets: |
          add_header my-test-header test-value;
    spec:
      rules:
      - host: cafe.example.com
        http:
          paths:
          - path: /tea
            backend:
              serviceName: tea-svc
              servicePort: 80
          - path: /coffee
            backend:
              serviceName: coffee-svc
              servicePort: 80